package com.beyond.trace.dy.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.beyond.trace.dy.domain.TraceDyOrder;
import com.beyond.trace.dy.service.ITraceDyOrderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采购订单Controller
 * 
 * @author Mr.Yao
 * @date 2022-04-09
 */
@RestController
@RequestMapping("/dy/order")
@Api(value = "采购订单", tags = "采购订单")
public class TraceDyOrderController extends BaseController
{
    @Autowired
    private ITraceDyOrderService traceDyOrderService;

    //@PreAuthorize("@ss.hasPermi('dy:Order:list')")
    @GetMapping("/list")
    @ApiOperation("查询采购订单列表")
    public TableDataInfo list(TraceDyOrder traceDyOrder)
    {
        startPage();
        List<TraceDyOrder> list = traceDyOrderService.selectTraceDyOrderList(traceDyOrder);
        return getDataTable(list);
    }

    //@PreAuthorize("@ss.hasPermi('dy:Order:query')")
    @GetMapping(value = "/query")
    @ApiOperation("查询采购订单列表不分页")
    public AjaxResult getInfoQuery(TraceDyOrder traceDyOrder)
    {
        return AjaxResult.success(traceDyOrderService.selectTraceDyOrderList(traceDyOrder));
    }

    //@PreAuthorize("@ss.hasPermi('dy:Order:export')")
    @Log(title = "采购订单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TraceDyOrder traceDyOrder)
    {
        List<TraceDyOrder> list = traceDyOrderService.selectTraceDyOrderList(traceDyOrder);
        ExcelUtil<TraceDyOrder> util = new ExcelUtil<TraceDyOrder>(TraceDyOrder.class);
        return util.exportExcel(list, "采购订单数据");
    }

    //@PreAuthorize("@ss.hasPermi('dy:Order:query')")
    @GetMapping(value = "/{orderId}")
    @ApiOperation("查询采购订单列表")
    public AjaxResult getInfo(@PathVariable("orderId") Long orderId)
    {
        return AjaxResult.success(traceDyOrderService.selectTraceDyOrderById(orderId));
    }

    //@PreAuthorize("@ss.hasPermi('dy:Order:add')")
    @Log(title = "采购订单", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增采购订单")
    public AjaxResult add(@RequestBody TraceDyOrder traceDyOrder)
    {
        return toAjax(traceDyOrderService.insertTraceDyOrder(traceDyOrder));
    }

    //@PreAuthorize("@ss.hasPermi('dy:Order:edit')")
    @Log(title = "采购订单", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改采购订单")
    public AjaxResult edit(@RequestBody TraceDyOrder traceDyOrder)
    {
        return toAjax(traceDyOrderService.updateTraceDyOrder(traceDyOrder));
    }

    //@PreAuthorize("@ss.hasPermi('dy:Order:remove')")
    @Log(title = "采购订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderIds}")
    @ApiOperation("删除采购订单")
    public AjaxResult remove(@PathVariable Long[] orderIds)
    {
        return toAjax(traceDyOrderService.deleteTraceDyOrderByIds(orderIds));
    }
}
